<template>
	<view class="transfer-container">
		<view class="form-container">
			<view class="form-group">
				<label for="receiveUserId">转账方用户ID</label>
				<input id="receiveUserId" v-model="form.receiveUserId" placeholder="请输入接收方用户ID" />
			</view>
			<view class="form-group">
				<label for="amount">转账金额</label>
				<input id="amount" v-model="form.amount" type="number" step="0.01" placeholder="请输入转账金额" />
			</view>
			<button class="transfer-button" @click="handleTransfer">转账</button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue"
	import PayWalletApi from "@/sheep/api/pay/wallet.js"
	const form = ref({
		receiveUserId: '',
		amount: ''
	});

	const handleTransfer = async () => {
		if (!form.value.receiveUserId) {
			showToast({
				title: '请输入接收方用户ID',
				icon: 'none'
			});
			return;
		}

		if (!form.value.amount) {
			showToast({
				title: '请输入转账金额',
				icon: 'none'
			});
			return;
		}

		try {
			const response = await PayWalletApi.getTransfer(form.value);
			if (response.code === 0) {
				uni.showToast({
					title: '转账成功',
					duration: 2000,
					icon: "none"
				});
				setTimeout(() => {
					uni.redirectTo({
						url: '/pages/me/Income_log?type=SURPLUS'
					});
				}, 1500);
			}
			console.log(response)
			// if (response.data.success) {
			//   showToast({ title: '转账成功', icon: 'success' });
			// } else {
			//   showToast({ title: '转账失败', icon: 'none' });
			// }
		} catch (error) {
			showToast({
				title: '网络请求出错',
				icon: 'none'
			});
		}
	};
</script>

<style scoped>
	.transfer-container {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100vh;
		background-color: #FAFAFA;
	}

	.form-container {
		width: 80%;
		background-color: #fff;
		padding: 25rpx;
		border-radius: 10px;
		box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
	}

	.form-group {
		margin-bottom: 20px;
	}

	.form-group label {
		display: block;
		margin-bottom: 5px;
		font-weight: bold;
	}

	.form-group input {
		width: 90%;
		padding: 10px;
		border: 1px solid #ccc;
		border-radius: 5px;
	}

	.transfer-button {
		width: 100%;
		padding: 10px;
		background-color: #54C5C1;
		color: #fff;
		border: none;
		border-radius: 5px;
		cursor: pointer;
		font-size: 16px;
	}

	.transfer-button:hover {
		background-color: #54C5C1;
	}
</style>